from django.db import models
from django.utils.html import format_html

'''
用户表
'''
class UserDb(models.Model):
    user_id = models.CharField(max_length=100,verbose_name='用户id')
    user_name = models.CharField(max_length=50,verbose_name='用户名称')
    user_img = models.CharField(max_length=250,verbose_name='用户图片')
    autograph = models.CharField(max_length=300,verbose_name='签名')

    def image_data(self):
        return format_html(
            '<img src="{}" width="100px"/>',
            self.user_img,
        )
    image_data.short_description = u'用户头像'

    class Meta:
        verbose_name = '微信用户'
        verbose_name_plural='微信用户'

'''
留言表
'''
class LeavDb(models.Model):
    leav_id = models.CharField(max_length=100,verbose_name='留言ID')
    user_id = models.CharField(max_length=100,verbose_name='关联用户ID')
    user_name = models.CharField(max_length=50, verbose_name='用户名称')
    user_img = models.CharField(max_length=250, verbose_name='用户图片')
    menu_url = models.CharField(max_length=150,verbose_name='菜谱ID')
    content = models.CharField(max_length=500,verbose_name='留言内容')
    praise = models.IntegerField(verbose_name='赞数')
    sttp_on = models.IntegerField(verbose_name='踩数')
    create_time = models.DateField(verbose_name='创建时间')
    update_time = models.DateField(verbose_name='修改时间')

    class Meta:
        verbose_name = '留言'
        verbose_name_plural = '留言'

'''
收藏表
'''
class collectionDb(models.Model):
    menu_id = models.CharField(max_length=150, verbose_name='菜谱ID')
    menu_name = models.CharField(max_length=100,verbose_name='菜谱名称')
    menu_img = models.CharField(max_length=250,verbose_name='菜谱封面图')
    menu_url =models.CharField(max_length=250,verbose_name='菜谱链接')
    user_id = models.CharField(max_length=100,verbose_name='用户ID')
    create_time = models.DateField(verbose_name='创建时间')
    update_time = models.DateField(verbose_name='修改时间')

    def image_data(self):
        return format_html(
            '<img src="{}" width="100px" height="100px"/>',
            self.menu_img,
        )

    image_data.short_description = u'封面图'

    class Meta:
        verbose_name = '收藏'
        verbose_name_plural = '收藏'